Package edu.claflin.finder.struct
Class PrioritySet<T>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.PriorityQueue<T>
edu.claflin.finder.struct.PrioritySet<T>
- Type Parameters:
T- the type of object to manage in the PriorityQueue.
- All Implemented Interfaces:
Serializable,Iterable<T>,Collection<T>,Queue<T>
Represents a PrioritySet. Operates as an extension of the
java.util.PriorityQueue in that it does not allow duplicate elements.
Furthermore, it may be configured so that on addition of similar elements
(i.e. elements that are equivalent via .equals() but have different weight
values) the higher of the two values is kept via comparator analysis.
That is to say, if a Comparator indicates that a newly added object should
come BEFORE the other object in a descending order, then the old object is
replaced. This can be leveraged to perform a descending-based replacement if
the comparator is configured properly. (i.e. a 4 replacing a 5.)
- Version:
- 1.1 May 28, 2015
- Author:
- Charles Allen Schultz II
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanBoolean indicating if newer elements with a greater compare value should replace others.private static final long -
Constructor Summary
ConstructorsConstructorDescriptionPrioritySet(boolean addOverride) Public constructor for initializing a PrioritySet.PrioritySet(Comparator<T> compare, boolean addOverride) Public constructor for initializing a PrioritySet. -
Method Summary
Methods inherited from class java.util.PriorityQueue
clear, comparator, contains, forEach, iterator, offer, peek, poll, remove, removeAll, removeIf, retainAll, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractQueue
addAll, element, removeMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
addOverride
private final boolean addOverrideBoolean indicating if newer elements with a greater compare value should replace others.
-
-
Constructor Details
-
PrioritySet
public PrioritySet(boolean addOverride) Public constructor for initializing a PrioritySet. Utilizes the natural ordering of the elements.- Parameters:
addOverride- a boolean indicating if new elements may override older ones based on the comparator's value.
-
PrioritySet
Public constructor for initializing a PrioritySet. Requires both a comparator for comparing elements and a boolean indicating if addOverride should be enabled.- Parameters:
compare- the Comparator to use for queue ordering.addOverride- a boolean indicating if new elements may override older ones based on the comparator's value.
-
-
Method Details
-
add
Allows additions of items that already has a copy within the set (determined by obj.equals(obj2) ) and their subsequent replacement if they are of lesser value than the new object as determined by the queue's comparator.- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceQueue<T>- Overrides:
addin classPriorityQueue<T>- Parameters:
t- the T type object to add.- Returns:
- true if added, false if not.
-